<template>
  <!-- 系统管理 -->
  <div class="app-container">
    <div class="mainbox">
      <!-- 顶部操作 -->
      <div class="filter-container">
        <el-form ref="filterFormRef" :inline="true" :model="filterForm">
          <el-form-item label="招引产业:" prop="industryCode">
            <el-select v-model.trim="filterForm.industryCode" placeholder="请选择" :clearable="true">
              <el-option
                v-for="dict in dict.type.zs_zycy"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="土地用途:" prop="landCode">
            <el-select v-model.trim="filterForm.landCode" placeholder="请选择" :clearable="true">
              <el-option
                v-for="dict in dict.type.zhzs_tdyt"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="联系人:" prop="contactsName">
            <el-input
              v-model.trim="filterForm.contactsName"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入联系人"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
          <el-form-item label="联系电话:" prop="contactsPhone">
            <el-input
              v-model.trim="filterForm.contactsPhone"
              class="filter-item limit"
              style="width: 200px;margin-right:10px"
              maxlength="30"
              clearable
              placeholder="请输入联系电话"
              @keyup.enter.native="$_handleFilter"
            />
          </el-form-item>
        </el-form>
        <div class="flex-1" />
        <el-button type="primary" @click="$_handleFilter">查询</el-button>
        <el-button @click="$_handleReset">重置</el-button>

      </div>
      <!-- 表格 -->
      <div class="table-container table-fullscreen">
        <div class="table-opt-container">
          <el-button
            v-permission="['URLANDSUPPLY_ADD_BUTTON']"
            type="primary"
            icon="el-icon-plus"
            @click="handleAdd"
          >
            新增
          </el-button>
          <el-button
            v-permission="['URLANDSUPPLY_DOWNLOAD_BUTTON']"
            icon="el-icon-download"
            @click="handleExport('d')"
          >
            下载模板
          </el-button>
          <el-button
            v-permission="['URLANDSUPPLY_IMPORT_BUTTON']"
            icon="el-icon-folder-add"
            type="primary"
            @click="$_handleImport()"
          >
            导入
          </el-button>
          <el-button
            v-permission="['URLANDSUPPLY_ON_BUTTON']"
            type="primary"
            icon="el-icon-open"
            @click="$_statusFlagChange([], 'Y', idKeyName, updateStatusApi,true)"
          >
            批量启用
          </el-button>
          <el-button
            v-permission="['URLANDSUPPLY_OFF_BUTTON']"
            icon="el-icon-turn-off"
            @click="$_statusFlagChange([], 'N', idKeyName, updateStatusApi, true)"
          >
            批量禁用
          </el-button>
          <div class="flex-1" />
          <dt-dialog-column :columns="columns" @queryTable="getList" />
        </div>
        <el-table
          ref="table"
          v-loading="MX_listLoading"
          :data="MX_list"
          border
          highlight-current-row
          :row-key="$_getRowKey"
          style="width: 100%;text-align:center"
          :header-cell-style="MX_headerCellStyle"
          @selection-change="$_handleSelectionChange"
        >
          <template slot="empty">
            <p>{{ $store.getters.dataText }}</p>
          </template>
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            fixed="left"
            type="index"
            label="序号"
            width="70"
            align="center"
            :index="$_tableIndex"
          />
          <el-table-column
            v-for="item in columns"
            :key="item.prop"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :min-width="item.minWidth"
            :formatter="item.formatter"
            align="center"
          />
          <el-table-column
            v-permission="['URLANDSUPPLY_ON_BUTTON', 'URLANDSUPPLY_OFF_BUTTON']"
            key="displayed"
            prop="displayed"
            label="是否启用"
            width="100px"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.displayed"
                class="tableScopeSwitch"
                active-value="Y"
                inactive-value="N"
                @change="(val) => $_statusFlagChange([scope.row[idKeyName]], val, idKeyName, updateStatusApi)"
              />
            </template>
          </el-table-column>
          <el-table-column
            :key="Math.random()"
            fixed="right"
            label="操作"
            width="220px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                class="tBtn"
                @click="$_handleDetail(scope.row)"
              >详情</el-button>
              <el-button
                v-permission="['URLANDSUPPLY_UPDATE_BUTTON']"
                size="mini"
                class="tBtn"
                @click="handleEdit(scope.row)"
              >修改</el-button>
              <el-button
                v-permission="['URLANDSUPPLY_DEL_BUTTON']"
                size="mini"
                type="danger"
                class="tBtn"
                @click="handleDelete(scope.row[idKeyName])"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <dt-pagination
          v-show="MX_total > 0"
          :total="MX_total"
          :page.sync="MX_pageNav.pageNo"
          :limit.sync="MX_pageNav.pageSize"
          @pagination="getList"
        />
      </div>
      <DialogForm ref="dialogForm" labelWidth="140px" :formDesignList="formDesignList" />
      <dtDialog
        title="导入"
        class="get-page-form-import-dialog"
        :visible.sync="MX_fileUploadVisible"
        width="620px"
        :is-loading="MX_uploadLoading"
        @closeDialog="MX_fileUploadVisible = false"
        @comfirmBtn="$_importDataSave(importApi, {parkId: parentId})"
      >
        <el-form slot="content">
          <div class="">
            <dt-importFile ref="dtImportFileRef" :down-load-template="handleImportTemplate" :type="fileName" />
          </div>
        </el-form>
      </dtDialog>
    </div>
  </div>
</template>
<script>
import DialogForm from '@/views/investment/components/DialogForm'
import commonList from "@/utils/mixins/investment/commonList";
import unifiedReportingApi from "@/api/investment/unifiedReporting";

export default {
  name: 'URLandSupply',
  components: {
    DialogForm
  },
  dicts: ['zs_zycy', 'zhzs_tdyt'],
  mixins: [commonList],
  data() {
    return {
      parentId: null,
      filterForm: {
        industryCode: '',
        landCode: '',
        contactsName: '',
        contactsPhone: ''
      },
      fileName: '供地数据导入',
      handleImportTemplate: unifiedReportingApi.downloadGD,
      importApi: unifiedReportingApi.importGD,
      updateStatusApi: unifiedReportingApi.updateStatusGD,
      // 列信息
      columns: [
        { prop: 'parkName', label: `所属园区`, width: '180px' },
        { prop: 'venueArea', label: `面积`, width: '160px' },
        { prop: 'industry', label: `招引产业`, width: '160px' },
        { prop: 'landUse', label: `土地用途`, width: '160px' },
        { prop: 'landExtent', label: `土地范围`, minWidth: '240px'  },
        { prop: 'contactsName', label: `联系人`, width: '100px' },
        { prop: 'contactsPhone', label: `联系电话`, width: '120px' }
      ],
      formDesignList: [
        { type: 'text', prop: 'parkName', label: `所属园区`, readonly: true, rules: [{ required: true, message: '请输入所属园区', trigger: 'blur' }] },
        { type: 'text', prop: 'venueArea', label: `面积`, rules: [{ required: true, message: '请输入面积', trigger: 'blur' }] },
        { type: 'select', prop: 'industryCode', label: `招引产业`, dictTypeCode: 'zs_zycy', rules: [{ required: true, message: '请输入招引产业', trigger: 'blur' }] },
        { type: 'select', prop: 'landCode', label: `土地用途`, dictTypeCode: 'zhzs_tdyt', rules: [{ required: true, message: '请输入土地用途', trigger: 'blur' }] },
        { type: 'text', prop: 'landExtent', label: `土地范围`, rules: [{ required: true, message: '请输入土地范围', trigger: 'blur' }] },
        { type: 'text', prop: 'contactsName', label: `联系人`, rules: [{ required: true, message: '请输入联系人', trigger: 'blur' }] },
        { type: 'text', prop: 'contactsPhone', label: `联系电话`, rules: [{ required: true, message: '请输入联系电话', trigger: 'blur' }, { pattern: /^(1[3456789]\d{9})$/, message: '请输入有效的联系电话', trigger: 'blur' }] },
      ],
      idKeyName: 'venueId'
    }
  },
  watch:{
    parentId(val, old){
      if (val !== old){
        this.getList()
      }
    }
  },
  created() {
    if (!this.$route.query.id){
      this.$message.error('请带入所属园区数据标识！')
      return
    }
    this.parentId = this.$route.query.id
  },
  activated() {
    this.parentId = this.$route.query.id
  },
  methods: {
    // 获取页面列表
    getList() {
      this.$_getList(unifiedReportingApi.getGDList,{
        parkId: this.parentId,
        ...this.filterForm,
        ...this.MX_pageNav
      })
    },
    // 编辑按钮
    handleEdit(data) {
      this.$refs.dialogForm.open('update', unifiedReportingApi.updateGDItem, data || this.MX_applicationMsg)
    },
    // 添加按钮
    handleAdd() {
      this.$refs.dialogForm.open('add', unifiedReportingApi.addGDItem, { parkId: this.parentId, parkName: this.MX_list[0].parkName })
    },
    // 删除按钮
    handleDelete(id) {
      this.$_handleDelete(unifiedReportingApi.delGDItem, [id], `${this.idKeyName}s`)
    },
    /** 下载按钮操作 */
    handleExport() {
      this.$_handleDownload(this.handleImportTemplate, `${this.fileName}模板`);
    },
  }
}
</script>

<style lang="scss" scoped>
.tBtn{
  margin-top: 3px;
  margin-bottom: 3px;
}
</style>
